home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Moscow ML 1.31 / source code / mosml / README.MacDev < prev    next >
Encoding:
Text File  |  1995-10-21  |  11.0 KB  |  299 lines  |  [TEXT/Moml]

  1. 21Oct95 e <e@flavors.com>
  2.  
  3. Read README.Mac first.
  4.  
  5. I used Metrowerks Codewarrior 6 to port Moscow ML 1.30.
  6. I used Metrowerks Codewarrior 7 to port Moscow ML 1.31.
  7. The Codewarrior 7 project files are included.
  8.  
  9. Because mosmlyac and runtime have identically named files in them, I 
  10. found it necessary to rename folder "runtime" to "!runtime" so Metrowerks 
  11. would choose the right files. I could have also solved this problem by 
  12. putting the project files into the runtime folder (as I did by putting the 
  13. mosmlyac project into mosmlyac) but I didn't. Why? I like to debug from the 
  14. Metrowerks debugger and so I want the project to live in the same directory 
  15. as the finished application.
  16.  
  17. The directory structure to three levels is as follows:
  18.  
  19. ANSIshellƒ                 -- the eConsole & eEdit sources
  20.    <lots of files>
  21. mosml folder
  22.    e_mac                   -- mosml <-> eConsole & MacOS glue
  23.       dirent.h
  24.       e_access.c
  25.       e_dirent.c
  26.       e_filelink.c
  27.       e_getenv.c
  28.       e_gettimeofday.c
  29.       e_graph.c
  30.       m.h
  31.       mac_os.c
  32.       mac_os.h
  33.       momlmenus.c
  34.       momlmenus.h
  35.       mosml.µ.rsrc
  36.       os_mac_cmdmenu.c
  37.       os_mac_options.h
  38.       s.h
  39.       sys/param.h
  40.       sys/resource.h
  41.       sys/stat.h
  42.       sys/time.h
  43.       sys/times.h
  44.       sys/types.h
  45.       sys/unistd.h
  46.       sys/utsname.h
  47.       ui.h
  48.       uio.c
  49.    mosml.image           -- toplevel includes make & link
  50.    mosml13m68            -- 68k application
  51.    mosml13m68.µ          -- 68k project
  52.    mosml13ppc            -- ppc application
  53.    mosml13ppc.µ          -- ppc project
  54.    mosmllexe             -- the lexer
  55.    README.Mac
  56.    README.MacDev
  57.    src
  58.       !runtime...
  59.       compiler...
  60.       lex...
  61.       mosmllib...
  62.       mosmlyac...
  63.       test...
  64.       tools...
  65.       toolssrc...
  66.  
  67. With all the files in place, mosml13m68 and mosml13ppc can be re-built 
  68. from the sources simply by opening their project files and doing 
  69. a Make. You'll need MetroWerks CodeWarrior 7. [It may be necessary to 
  70. fix a path for ANSIShellƒ in the Load Paths preferences. In version 7 
  71. CodeWarrior seems to have forgotten how to maintain relative paths.]
  72.  
  73. Well, I lied. There's a bit of pre-processing of the files that in UNIX 
  74. versions of mosml takes place via sed, awk, perl, cpp, etc. Some of these 
  75. intermediate files are provided in this Mac version in the xtra folder. 
  76. If you have sed, awk, perl, cpp, etc. then you may prefer to grok the 
  77. make scripts and generate these files yourself -- it is safer to do so 
  78. since they are generated from sources independent of this archive.
  79.  
  80. Here are some basic rules:
  81.  
  82. .grm files are processed by mosmlyac, which is supplied. Move mosmlyac 
  83. temporarily to the folder with the .grm file, launch it, type in the .grm 
  84. file name, and that's it. Move mosmlyac back to its folder.
  85.  
  86. .lex files are processed with mosmllex, which is also supplied. The file 
  87. !macuseful.sml has a few command lines which can be used with mosml to 
  88. process the .lex files in the usual distribution.
  89.  
  90. .mlp files are processed by cpp, the C pre-processor. I do this by hand 
  91. since the MetroWerks compiler is freaked out by ML syntax.
  92.  
  93. A few other files must be created using sed, awk, and perl. I've supplied
  94. all of these intermediate files since these tools are not widely used on 
  95. the Mac. A few perl droplets are supplied anyway in case you need to redo 
  96. my work. Drop runtime's instruct.h onto mksmlopc to make Opcodes.sml. 
  97. Launch mksmlpre and supply the command line...
  98.   ::!runtime:globals.h ::!runtime:fail.h
  99. to make Predef.sml. Making Prim_c.sml (and prims.c) is harder since it 
  100. first requires making the file "primitives" [which requires sed and awk 
  101. and running a UNIX shell script, if you believe the make file]. Once you 
  102. have primitives [I made mine by hand] you can drop it onto mksmlprc to make 
  103. Prim_c.sml.
  104.  
  105. If you already have the mosml object files in your mosmllib (e.g., from 
  106. the application release), the following  step isn't necessary, just 
  107. launch mosml13m68 or mosml13ppc. This step is only necessary when there 
  108. are no object files in the mosmllib...
  109.  
  110. With the existing or new mosml13m68 or mosml13ppc, you can recreate all 
  111. the mosml object files by launching with the command key down and 
  112. entering the command line:
  113.   :mosml.image -P none -stdlib <path to mosml folder>:src:mosmllib:
  114.  
  115. Then evaluate:
  116.  
  117. val home = "Bang"; (* your path to the mosml folder goes here! *)
  118.  
  119. moolevel := 2;
  120.  
  121. (* to compile the toplevel mosml image and the lexer *)
  122.  
  123. let val base = home ^ ":mosml:src:"
  124. in
  125.   make "none" (base ^ "mosmllib") [] (base ^ "mosmllib");
  126.   make "none" (base ^ "mosmllib") [] (base ^ "compiler");
  127.   make "none" (base ^ "mosmllib") [(base ^ "compiler")] (base ^ "toolssrc");
  128.   make "none" (base ^ "mosmllib") [(base ^ "compiler")] (base ^ "lex")
  129. end;
  130.  
  131. (* to build the toplevel mosml image into file "testtop.image" *)
  132.  
  133. let val base = home ^ ":mosml:src:"
  134. in
  135.   chDir base; chDir "::";
  136.   link "testtop.image"
  137.        (true,true) (* -g -noheader *)
  138.        "lorder" (base ^ "mosmllib") [(base ^ "compiler"),(base ^ "toolssrc")]
  139.        ["Maine.uo"]
  140. end;
  141.  
  142. (* another way to build the toplevel mosml image into file "testtop.image" *)
  143.  
  144. let val base = home ^ ":mosml:src:"
  145. in
  146.   chDir base; chDir "::";
  147.   link "testtop.image"
  148.        (true,true) (* -g -noheader *)
  149.        "none" (base ^ "mosmllib") [(base ^ "compiler"),(base ^ "toolssrc")]
  150.  
  151.        ["List.uo", "Char.uo", "Strbase.uo", "String.uo", "BasicIO.uo",
  152.         "Vector.uo", "Misc.uo", "Array.uo", "StringCvt.uo", "Word8.uo",
  153.         "Word8Vector.uo", "CharVector.uo", "Word8Array.uo", "CharArray.uo",
  154.         "Obj.uo", "Nonstdio.uo", "Substring.uo", "Path.uo", "Time.uo",
  155.         "OS.uo", "FileSys.uo", "Lexing.uo", "Parsing.uo", "Miscsys.uo",
  156.         "Printexc.uo", "Filename.uo", "Fnlib.uo", "Sort.uo", "Stack.uo",
  157.         "Arg.uo", "Hasht.uo", "Memory.uo", "Config.uo", "Mixture.uo",
  158.         "Const.uo", "Smlexc.uo", "Prim.uo", "Instruct.uo", "Lambda.uo",
  159.         "Smlprim.uo", "Globals.uo", "Location.uo", "Units.uo", "Types.uo",
  160.         "Smlperv.uo", "Asynt.uo", "Asyntfn.uo", "Parser.uo", "Lexer.uo",
  161.         "Primdec.uo", "Infixst.uo", "Ovlres.uo", "Synchk.uo", "Infixres.uo",
  162.         "Elab.uo", "Tr_env.uo", "Pr_lam.uo", "Match.uo", "Front.uo",
  163.         "Back.uo", "Pr_zam.uo", "Opcodes.uo", "Prim_opc.uo", "Buffcode.uo",
  164.         "Labels.uo", "Code_dec.uo", "Reloc.uo", "Emitcode.uo", "Emit_phr.uo",
  165.         "Sigmtch.uo", "Crc.uo", "Compiler.uo", "Predef.uo", "Prim_c.uo",
  166.         "Symtable.uo", "Patch.uo", "Tr_const.uo", "Rtvals.uo", "Load_phr.uo",
  167.         "Exec_phr.uo", "Link.uo", "Deppars.uo", "Deplex.uo",
  168.         "Smltope.uo", "Maine.uo"]
  169. end;
  170.  
  171. (* to build the lexer into file "mosmllex" *)
  172.  
  173. let val base = home ^ ":mosml:src:"
  174. in
  175.   chDir base; chDir "::";
  176.   link "mosmllex"
  177.        (true,true) (* -g -noheader *)
  178.        "none" (base ^ "mosmllib") [(base ^ "lex"),(base ^ "compiler")]
  179.  
  180.        ["List.uo", "Vector.uo", "Array.uo", "Char.uo", "Strbase.uo", 
  181.         "String.uo", "StringCvt.uo", "Word8.uo", "Word8Vector.uo", 
  182.         "Word8Array.uo", "CharVector.uo", "CharArray.uo", "Obj.uo", 
  183.         "BasicIO.uo", "Nonstdio.uo", "Lexing.uo", "Parsing.uo", 
  184.         "Miscsys.uo", "Printexc.uo", "Filename.uo", "Fnlib.uo", 
  185.         "Sort.uo", "Arg.uo", "Hasht.uo", "Syntax.uo", "Scan_aux.uo", 
  186.         "Gram_aux.uo", "Grammar.uo", "Scanner.uo", "Lexgen.uo", 
  187.         "Output.uo", "Mainlex.uo"]
  188. end;
  189.  
  190. (* *)
  191.  
  192. This section is probably only of historical interest.
  193.  
  194. Here is some detail about what I have done to make mosml work on the 
  195. Mac...
  196.  
  197. I already had The Caml Light 0.7 runtime working on the Mac with my own 
  198. console/editor environment. This code (which I'll call eConsole) 
  199. supplies some of the missing UNIX functions such as timers for user, 
  200. system, and gc, and of course, terminal i/o. Also for Caml Light and 
  201. SML/NJ, I had implemented UNIX -> Mac pathname translation and included 
  202. it in the runtime. This supports using UNIX created images (e.g., 
  203. mosmlcmp) in the Mac environment.
  204.  
  205. So, step one was diff'ing mosml 1.30 and my custom Caml Light 0.7 
  206. runtimes to merge my stuff in. This was not hard; although mosml seems 
  207. to be based on an early 0.7 beta, I got my stuff in easily. A few 
  208. changes were required for the MetroWerks 68k compiler. I  also added in 
  209. my user, system, and gc timer.
  210.  
  211. Then I created replacements for some of the missing UNIX functions. 
  212. These include access, readdir, etc. I also made several files such as 
  213. "sys/unistd.h" that are simply one line: #include <unistd.h>. This makes 
  214. modification of the mosml sources that include "sys/xxx.h" files 
  215. unnecessary. It also makes a convenient place to put special unixfoolery 
  216. such as defining F_OK, and overriding MWERKS flawed implementations, 
  217. e.g., of chdir.
  218.  
  219. It was also necessary to add a couple macros to mosml.c to adjust the 
  220. Mac time (1904 base) to UNIX time (1970 base) and back.
  221.  
  222. Then I could compile and link the world. I did this one file at a time. 
  223. [Now that I have made make, this will never again be necessary!?]
  224.  
  225. The SML changes I made were few.
  226.  
  227. In mosmllib I hooked in my gc timer (UNIX and DOS don't have one), I 
  228. hooked in osInfo (sml_uname), and fixed or worked around a couple bugs 
  229. [these are now reported/fixed]. The changed files are:
  230.  
  231. Mosml.sml  gc timer
  232. Timer.sml  gc timer
  233. OS.sml     sml_uname (should be changed: OS.mlp)
  234.  
  235. FileSys.sml  -- I used the DOS version at first, then custom
  236. Path.sml     -- I used the UNIX version at first, then custom
  237.  
  238. and these files which, I think, are equivalent to what cpp would have 
  239. done:
  240.  
  241. Array.sml
  242. Integer.sml
  243. Strbase.sml
  244. Vector.sml
  245. Word.sml
  246. Word8Array.sml
  247. Word8Vector.sml
  248.  
  249. In compiler I changed:
  250.  
  251. Smltop.sml   to add chDir and gc_full_major
  252. Link.sml     to make missing_globals a ref
  253. Symtable.sml to add protect_linker_tables
  254. Symtable.sig to make this visible
  255.  
  256. The purpose of the linker chages is twofold. In order to do a link in a 
  257. toplevel environment it is necessary to save and restore the current 
  258. environment. All the effected data are in the Symtable unit [as I said 
  259. above, this isn't well tested]. protect_linker_tables was added to to 
  260. this job. The second part of the change in to make missing_globals a 
  261. ref. This change was also made by INRIA at my request in Caml Light. 
  262. This is needed because the missing_globals hashtable gets very big for 
  263. some links, and never shrinks. In fact is seems to get bigger with 
  264. every link. To conserve memory the new link disposes the table after 
  265. every link.
  266.  
  267. I also created:
  268.  
  269. Opcodes.sml
  270. Predef.sml
  271. Parser.sig
  272. Parser.sml
  273. Filename.sml
  274. Config.sml
  275. Lexer.sml
  276.  
  277. from the requisite sources.
  278.  
  279. Then I added the new sources for Smltope and Maine.
  280.  
  281. The only files I changed in runtime are:
  282.  
  283. mosml.c      Mac <-> UNIX time, e_getrusage
  284. floats.c     used Caml Light 0.7 version (has my compiler fixes)
  285. misc.c       kill bogus malloc prototype
  286. minor_gc.c   gc timer
  287. major_gc.c   gc timer
  288. misc.h       includes <stdlib.h> for malloc bug
  289. prims.c      generated file
  290. main.c       [I don't remember,  I'll diff it later]
  291. interp.c     punt spin (it's in ui.h)
  292. fail.c       #define MAXDOUBLE
  293. config.h     MWERKS friendly m.h & s.h includes
  294. sys.c        UNIX -> Mac pathname translation
  295.  
  296. I also added a bunch of new files for eConsole and unixfoolery.
  297.  
  298. e
  299.